package com.aaa.controller;

import com.aaa.entity.ReturnData;
import com.aaa.service.BusinessService;
import com.aaa.service.impl.BusinessServiceImpl;
import com.aaa.util.MyConstants;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/7/19 9:57
 * @description：活动的业务控制器
 * @modified By：
 * @version: 1.0
 */
@WebServlet(urlPatterns = "/business")
public class BusinessController extends  BaseController {
    BusinessService businessService = new BusinessServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //调用父类的通用参数初始化方法
        Map<String, String> map = super.initParam(req, resp);
        //判断方法名
        String method=map.get("method")+"";
        ReturnData returnData = new ReturnData();
        switch (method){
            case "findAllBusiness":
                List<Map<String, Object>> allUser = businessService.findAllBusiness(map);
                //回传json数据

                returnData.setCode(0);
                //获取数据库表的总条数
                int count = businessService.getCount(map);
                returnData.setCount(count);
                returnData.setData(allUser);
                //调用父类的通用方法
                super.toJsonString(returnData,resp);
                break;
            case "addUser":
                break;
            case "outlineBusinessById":
                //下线活动，修改操作
                boolean outlineBusinessById = businessService.outlineBusinessById(map);
                if(outlineBusinessById){
                    super.returnSuccess(returnData);
                }else
                {
                    super.returnFail(returnData);
                }
                super.toJsonString(returnData,resp);
                break;
            case "getCountApply":
                //获取统计数据
                List<List<String>> applyCount = businessService.getApplyCount();
                returnData.setData(applyCount);
                //返回json字符串
                ReturnData data = super.returnSuccess(returnData);
                super.toJsonString(data,resp);
                break;
            default:
                System.out.println("参数错误");
                break;
        }
    }
}
